
// #ifndef VUE3
import Vue from 'vue'
import App from './App'
import uView from '@/uni_modules/uview-ui'
import store from './store/store.js'

import { $http } from '@escook/request-miniprogram'
uni.$http = $http

// $http.baseUrl = 'http://43.138.188.66:8160'
$http.baseUrl = 'https://www.lzlfhzwp666.fun'
$http.beforeRequest = function(options) {
  uni.showLoading({
    title:"数据加载中...."
  })
  if(options.url.indexOf('/tokenTest') !== -1){
    // 设置请求头
    options.header =  {
      'Authorization': JSON.parse((uni.getStorageSync('token'))),
      'Content-Type': 'application/json'
    }
  }
  if(options.url.indexOf('/api') !== -1){
    options.header =  {
      'Authorization': JSON.parse((uni.getStorageSync('token'))),
      'Content-Type': 'application/json'
    }
  }
}

$http.afterRequest = function() {
  uni.hideLoading()
  // 提示登录已过期
  // if(!uni.getStorageSync('tokenTest')) {
  //     uni.showModal({
  //       title: '提示',
  //       content: '登录信息已过期，请重新登录',
  //       showCancel: false,
  //       confirmText: '去登录',
  //       success(res) {
  //         if(res.confirm) {
  //           uni.switchTab({
  //               url: '/pages/mine/mine'
  //           })
  //         } 
  //       },
  //     })
  // }
}

// 挂载验证token是否过期方法,res为false还没过期，为true则已经过期
// uni.$tokenTest = async function() {
//   const {data:res} = await uni.$http.get('/tokenTest')
//   uni.setStorageSync('tokenTest',res)
// }

// 设置红点
uni.$setBadge = function() {
  if(uni.getStorageSync('isDot') || false) {
    uni.showTabBarRedDot({
      index: 2, // 索引
      // text: ''
    })
  } else {
    uni.hideTabBarRedDot({
    	index : 2,
    })
  }
}
Vue.use(uView)



uni.$showMsg = function(title = "数据请求失败!" , duration = 1500) {
  uni.showToast({
    title,
    duration,
    icon:"none"
  })
}

Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
    ...App,
    store
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
import App from './App.vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif